/**
 * 
 */
package pl.lodz.p.browarex.model;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;

@Entity(name = "INGREDIENT")
public class Ingredient {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "INGREDIENTID")
	private Long id;
	
	@Column(name = "GUID", nullable = false)
	private String ingredientId;
	
	@Column(name = "NAME", nullable = false, length = 50)
	private String name;
	
	@Column(name = "AMOUNT", nullable = false)
	private double amount;
	
	@ManyToMany(fetch = FetchType.LAZY, mappedBy = "ingredients")
	private List<Product> products = new ArrayList<Product>();

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "ingredient")
	private List<IngredientOrderInfo> ingredientOrderInfo = new ArrayList<IngredientOrderInfo>();

	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	

	public void setId(Long id) {
		this.id = id;
	}


	public List<Product> getProducts() {
		return products;
	}

	public void setProducts(List<Product> products) {
		this.products = products;
	}

	public List<IngredientOrderInfo> getIngredientOrderInfo() {
		return ingredientOrderInfo;
	}

	public void setIngredientOrderInfo(List<IngredientOrderInfo> ingredientOrderInfo) {
		this.ingredientOrderInfo = ingredientOrderInfo;
	}

	public String getIngredientId() {
		return ingredientId;
	}

	public void setIngredientId(String ingredientId) {
		this.ingredientId = ingredientId;
	}

	public Long getId() {
		return id;
	}

	public double getAmount() {
		return amount;
	}

	public void setAmount(double amount) {
		this.amount = amount;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(amount);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result
				+ ((ingredientId == null) ? 0 : ingredientId.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Ingredient other = (Ingredient) obj;
		if (Double.doubleToLongBits(amount) != Double
				.doubleToLongBits(other.amount))
			return false;
		if (ingredientId == null) {
			if (other.ingredientId != null)
				return false;
		} else if (!ingredientId.equals(other.ingredientId))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Ingredient [id=").append(id).append(", ingredientId=")
				.append(ingredientId).append(", name=").append(name)
				.append(", amount=").append(amount).append("]");
		return builder.toString();
	}
	
}
